package cn.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class code {
	public static void main(String[] args) {
		String url = "jdbc:mysql://localhost:3306/student";
		String username = "root";
		String password = "123456";
		String outputDir = "E:\\student_end\\back\\generator\\src\\main\\java";
		String basePackage = "cn.generator";
		String mapperLocation = "E:\\student_end\\back\\generator\\src\\main\\resources\\mapper";
		String tableName = "s_user_health";
		String tablePrefix = "s_";
		FastAutoGenerator.create(url, username, password)
			.globalConfig(builder -> {
				builder.outputDir(outputDir) // 指定输出目录
					.disableOpenDir();
			})
			.packageConfig(builder -> {
				builder.parent(basePackage) // 设置父包名
					.pathInfo(Collections.singletonMap(OutputFile.xml, mapperLocation)); // 设置mapperXml生成路径
			})
			.strategyConfig(builder -> {
				builder.addInclude(tableName) // 设置需要生成的表名
					.addTablePrefix(tablePrefix) // 设置过滤表前缀
					.entityBuilder()
//					.disableSerialVersionUID()
					.enableTableFieldAnnotation()
					.enableLombok()
					.enableChainModel()
					.controllerBuilder()
					.enableRestStyle()
					.enableHyphenStyle()
					.mapperBuilder()
					.enableMapperAnnotation()
					.enableBaseResultMap()
					.enableBaseColumnList();

			})
			.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
			.execute();
	}
}
